import router from './router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import store from './store'
import { Message } from 'element-ui'

NProgress.configure({ showSpinner: false }) // NProgress Configuration
// 白名单
const whiteList = ['/login']
router.beforeEach(async(to, from, next) => {
  NProgress.start()
  const token = store.getters.token
  if (token) {
    next()
    return
  }
  if (whiteList.includes(to.path)) {
    next()
    return
  }
  Message.info('请重新登录')
  next('/login')
  NProgress.done()
})

router.afterEach(() => {
  NProgress.done()
})
